#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ = '__Jack__'

from fastapi import APIRouter, Depends, HTTPException
from fastapi.responses import JSONResponse, Response
from database import get_db
from sqlalchemy.orm import Session
from app.yg_crm import schemas, crud, orm
from typing import List, Optional
from utility.utility import result, RespResult, json_result_reps

user_router = APIRouter()


@user_router.get("/get_user", response_model=Optional[RespResult],
                 response_model_exclude_unset=True, response_model_exclude_none=True)
def get_user(user_id: str, db: Session = Depends(get_db)):
    user = crud.get_user(db, user_id=user_id)
    if not user:
        raise HTTPException(status_code=404, detail="user do not exists")
    return result(data=user, schema=schemas.User)


@user_router.get("/get_users", response_model=Optional[RespResult],
                 response_model_exclude_unset=True, response_model_exclude_none=True)
def get_users(db: Session = Depends(get_db)):
    users = crud.get_users(db)

    if not users:
        raise HTTPException(status_code=404, detail="users do not exists")
    return result(data=users, schema=schemas.User)


"""
typing.List[app.yg_crm.orm.user.User] is a valid Pydantic field typ
response_model，response_model_exclude_unset，response_model_exclude_none都是针对pydantic model的
"""









